﻿using Presenters.WPF;
using Presenters.WPF.Views;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace AirlinePilotAcademy_WPF.UI_Administrator.Classroom
{
    /// <summary>
    /// Lógica de interacción para SearchClassroom.xaml
    /// </summary>
    public partial class SearchClassroom : Window, ISearchClassroom
    {
        SearchClassroomPresenter presenter;
        private string Message;

        public SearchClassroom()
        {
            InitializeComponent();

            presenter = new SearchClassroomPresenter(this);
            presenter.SearchClassroom();
        }        

        public string searchFilter
        {
            get { return (this.TextBox_filter.Text); }
        }
        public bool realTimeSearch
        {
            get { return (this.CheckBox_RealTimeSearch.IsChecked == true); }
        }
        public Collection<Model.Classroom> results
        {
            set { this.DataGrid_result.ItemsSource = value; }
        }
        public string message
        {
            set { Message = value; }
        }
        public Model.Classroom selectedClassroom
        {
            get { return (Model.Classroom)this.DataGrid_result.SelectedItem; }
        }        
        

        private void CheckBox_checkedRealTimeSearch(object sender, RoutedEventArgs e)
        {
            if (presenter != null)
            {
                this.Button_Search.IsEnabled = false;
            }
        }

        private void CheckBox_uncheckedRealTimeSearch(object sender, RoutedEventArgs e)
        {
            if (presenter != null)
            {
                this.Button_Search.IsEnabled = true;
            }
        }

        private void TextBox_FilterChanged(object sender, TextChangedEventArgs e)
        {
            if (presenter != null)
            {
                presenter.SearchClassroomRealTime();
            }
        }

        private void Button_Search_Click(object sender, RoutedEventArgs e)
        {
            if (presenter != null)
            {
                presenter.SearchClassroom();
            }
        }

        private void DataGrid_SelectedItem(object sender, MouseButtonEventArgs e)
        {
            if (this.DataGrid_result.SelectedItem != null)
            {
                this.Button_ModifyClassroom.IsEnabled = true;
                this.Button_WatchInfoClassroom.IsEnabled = true;
            }
        }

        private void Button_Click_ModifyClassroom(object sender, RoutedEventArgs e)
        {
            if (this.DataGrid_result.SelectedItem != null)
            {
                ClassroomObject viewInfoSubject = new ClassroomObject((Model.Classroom)this.DataGrid_result.SelectedItem);
                viewInfoSubject.ShowDialog();
            }
        }

        private void Button_Click_WatchInfoClassroom(object sender, RoutedEventArgs e)
        {
            if (this.DataGrid_result.SelectedItem != null)
            {
                ClassroomObject viewInfoSubject = new ClassroomObject((Model.Classroom)this.DataGrid_result.SelectedItem, "Cerrar");
                viewInfoSubject.ShowDialog();
            }
        }
    }
}
